package com.michael.demos.springboot.flux.controller;

import com.michael.demos.springboot.flux.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * 类功能描述:
 * <pre>
 *   WebFlux使用示例
 * </pre>
 *
 * @author Michael
 * @version 1.0
 * @date 2020/8/18 15:48
 */
@RestController
public class FluxController {

    @RequestMapping("hello/{who}")
    public Mono<String> hello(@PathVariable String who) {
        return Mono.just(who)
                   .map(w -> "Hello " + w + "!");
    }

    @GetMapping("/hello")
    public String hello() {
        return "Hello, WebFlux !";
    }

    @GetMapping("/user")
    public Mono<User> getUser() {
        User user = new User();
        user.setName("Michael");
        user.setDesc("就是这样");
        return Mono.just(user);
    }
}
